home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1996 April / Macworld (1996-04).dmg / Shareware World / Entertainment / General / Xconq 7.0.1 / doc / hacking.texi (.txt) < prev    next >
Texinfo Document  |  1995-08-22  |  50KB  |  983 lines

  1. @node Hacking Xconq, , Reference Manual, Top
  2. @chapter Hacking Xconq
  3. Although @i{Xconq} and its GDL have considerable power and flexibility
  4. already built in,
  5. you may decide that you want to modify the @i{Xconq} program itself.
  6. You should know what you are doing;
  7. @i{Xconq} is designed to be modifiable, but it is not simple code.
  8. In the past, people have found it easy to make changes,
  9. but much harder to make them correctly!
  10. @i{Xconq} is designed to be portable to different types of user interfaces.
  11. It is based on a kernel-interface architecture, where the semantics of
  12. the game, as documented in the preceding chapters, is part of the kernel,
  13. while the main program and player interaction are specific to each system.
  14. @i{Xconq} is also designed to allow the addition of new AIs.  The default
  15. @code{"mplayer"} AI, while it is flexible and will attempt to play any side
  16. in any game, does not have the depth that is often important to success
  17. in a game.  Its position is that of a generic AI program that can learn to
  18. play any game, given only the rules; while such a program might figure out
  19. how to win at tic-tac-toe or checkers, it is not going to be particularly
  20. good at the subtleties of go or chess.
  21. The @i{Xconq} GDL is also extensible.  This is useful when the basic GDL
  22. does not provide some feature that is essential to a game.
  23. @menu
  24. * Kernel::                      
  25. * Interface::
  26. * Networking::                  
  27. * Miscellany::                  
  28. @end menu
  29. @node Kernel, Interface, Hacking Xconq, Hacking Xconq
  30. @section Kernel
  31. The kernel is the part of @i{Xconq} shared by all interfaces.
  32. It does no I/O except to files or for debugging.
  33. Specifically, the kernel supplies the following functionality:
  34. @itemize
  35. @item
  36. Data structure initialization. (@code{init_data_structures})
  37. @item
  38. Game module loading and interpretation. (@code{load_game_module})
  39. @item
  40. Initial player/side setup. (@code{make_trial_assignments})
  41. @item
  42. Synthesis methods. (@code{run_synthesis_methods})
  43. @item
  44. Final player/side setup. (@code{make_assignments})
  45. @item
  46. Game execution. (@code{run_game})
  47. @item
  48. Implementations of unit actions. (@code{prep_*_action})
  49. @item
  50. AI players.
  51. @item
  52. Help Info (@code{get_help_text})
  53. @item
  54. Game saving and scorekeeping.
  55. @end itemize
  56. @menu
  57. * Configuration Options::       
  58. * Porting the Kernel::          
  59. * Writing New Synthesis Methods::  
  60. * Writing New Namers::          
  61. * Writing New AIs::             
  62. * Extending GDL::               
  63. @end menu
  64. @node Configuration Options, Porting the Kernel, Kernel, Kernel
  65. @subsection Configuration Options
  66. There are a small number of options available to alter aspects of
  67. the kernel.  These are defined in @code{kernel/config.h}.
  68. [eventually describe all of them?]
  69. @node Porting the Kernel, Writing New Synthesis Methods, Configuration Options, Kernel
  70. @subsection Porting the Kernel
  71. The kernel should be restricted to ANSI C, and should avoid or optionalize
  72. features not in ``traditional'' C, such like prototypes.
  73. Although the kernel uses stdio,
  74. it does not assume the presence of a console (stdin, stdout, stderr).
  75. For instance, a graphical interface can arrange to disable stdin entirely
  76. and direct stdout/stderr into a file (see the Mac interface sources
  77. for an example).
  78. You should be careful about memory consumption.  In general, the kernel
  79. takes the attitude that if it was worth allocating, it's worth hanging
  80. onto; and so the program does not free much storage.  Also, nearly all
  81. of the allocation happens during startup.  Since a game may run for a
  82. very long time (thousands of turns perhaps), it is important not to
  83. run the risk of exhausting memory at a climactic moment in the game!
  84. Also, the kernel should not exit on its own.  The only permissible
  85. times are when the internal state is so damaged that interface
  86. error-handling routines (see below) cannot be called safely.
  87. Such situations are rare.  If you add something to the kernel
  88. and need to handle error situations, then you should call one
  89. of the interface's error-handling routines.
  90. There are distinct routines for problems during initializations
  91. vs problems while running, and both error and warning routines.
  92. Warning routines may return, so kernel code should be prepared
  93. to continue on, while error routines will never return.
  94. @node Writing New Synthesis Methods, Writing New Namers, Porting the Kernel, Kernel
  95. @subsection Writing New Synthesis Methods
  96. You can add new synthesis methods to @i{Xconq}.
  97. This may be necessary if an external program
  98. does not exist, is unsuitable, or the external program
  99. interface is not available.
  100. Synthesis methods should start out by testing whether or not to run,
  101. and should never assume that any other method has been run before or
  102. after, nor that any particular game module has been loaded.
  103. However, ``tricks'' are usually OK, such as setting a particular global
  104. variable in a particular module only, then having the synthesis method
  105. test whether that global is set.
  106. See the file @code{init.c} for further details.
  107. Synthesis methods that take longer than a second or two to execute
  108. should generate percent-done info for the interface to use,
  109. via the function @code{announce_progress}.
  110. Be aware that most methods will be O(n) or O(n*n) on the
  111. size of the world or the number of units,
  112. so they can take much longer to set up
  113. a large game than a small one.
  114. Players will often go overboard and start up giant games,
  115. so this happens frequently.
  116. Also, @i{Xconq} may be running on a much smaller and slower
  117. machine than what you're using now.
  118. @node Writing New Namers, Writing New AIs, Writing New Synthesis Methods, Kernel
  119. @subsection Writing New Namers
  120. [describe hook and interface]
  121. @node Writing New AIs, Extending GDL, Writing New Namers, Kernel
  122. @subsection Writing New AIs
  123. You can add new types of AIs to @i{Xconq}.
  124. You would do this to add different strategies as well as
  125. to add AIs that are programmed specifically for a single game or
  126. class of games.  (This is useful because the generic AI does not
  127. always understand the appropriate strategy for each game.)
  128. You have to design the object that is the AI's ``mental state''.
  129. If your AI need only react to the immediate situation, then this
  130. object can be very simple, but in general you will need to design
  131. a fairly elaborate structure with a number of substructures.
  132. Since there may be several AIs in a single game, you should be
  133. careful about using globals, and since @i{Xconq} games may often
  134. run for a long time, you should be careful not to consume memory
  135. recklessly.
  136. @itemize
  137. @item
  138. Name.
  139. This is a string, such as @code{"mplayer"}.
  140. It may be displayed to players, so it should not be too cryptic.
  141. @item
  142. Validity function.
  143. This runs after modules are loaded, and during player/side
  144. setup, and decides whether it can be in the given game on the given side.
  145. [have a chain of fallback AIs, or blow off the game?]
  146. @item
  147. Game init function.  This runs before displays are set up, just in case
  148. a display needs to examine the AI's data (for instance to display whether
  149. the AI is friendly or unfriendly).
  150. The game init function should also look for and interpret the contents
  151. of the side's @code{aidata}, if appropriate.  The generic game reading code
  152. fills the slot, but does not interpret the data further.
  153. @item
  154. Turn init function.  This runs after all the units get their acp and mp
  155. for the turn, but before anybody actually gets to move.
  156. @item
  157. Unit order function.  This gets run to decide what the unit should do.
  158. Usually it should be allowed to follow its plan.
  159. [do separate fns for before and after plan execution?]
  160. @item
  161. Event reaction functions. [how many?]
  162. @item
  163. State save function.  This formats state that should be saved into
  164. a Lisp object.  The game saving code then writes this state into
  165. the file so that it can be read in again.  You may not do any
  166. allocation while saving a game however, so if you need space (and
  167. note that even a single cons allocates space), you must have the AI
  168. init routine or some such do the allocation early on, then reuse
  169. the space.
  170. @end itemize
  171. Note that these functions have very few constraints, so you can write them
  172. to work together in various ways.  For instance, an AI can decide whether
  173. to resign once/turn, once/action, or once for each 4 units it moves, every
  174. other turn.
  175. [describe default AI as illustrative example]
  176. @node Extending GDL, , Writing New AIs, Kernel
  177. @subsection Extending GDL
  178. GDL has been designed so as to be relatively easily extensible.
  179. I say ``relatively'' because although it is quite easy to define a new
  180. keyword or table, it is not always so easy to integrate the implementation
  181. code into the kernel correctly.
  182. Instead of actually changing GDL, you can experiment with an addition
  183. by using the @code{extensions} property of unit, material, and terrain types.
  184. In the code, you call @code{get_u_extension}, pass it the type, name
  185. of the property, and a default to return if the value was not given.
  186. In the game definition, the designer would say
  187. @code{(unit town (extensions (my-ext xxx)))}.
  188. [show examples for global, property, table, event, task]
  189. The file @code{gvar.def} defines all the global variables.
  190. The file @code{utype.def} defines all the unit type properties.
  191. From time to time, it may be worthwhile to extend unit objects.
  192. This should be rare, because games may have thousands of units,
  193. and each unit requires at least 100 bytes of storage already,
  194. so you should avoid making them any larger.
  195. Properties of an individual unit are scattered through @code{keyword.def}.
  196. Once the structure slot is added, you just need to add reading and
  197. writing of the value, using the @code{K_@var{xxx}} enum that was
  198. defined with the keyword.  You should attempt to make a reasonable
  199. default and use it to avoid writing out the value, so as to save
  200. time when @i{Xconq} reads a game in.
  201. GDL symbols beginning with @code{zz-} should be reserved for the use
  202. of AI code.  You may want to add some of these, either to serve as a
  203. convenient place for AIs to cache the results of their analyis of a
  204. game, or else as a way for game designers to add ``hints'' for AIs
  205. that know to look at them.
  206. Note that all the @samp{*.def} files together are to define the exact set
  207. of symbols defined by GDL.  You should not add any expedient matching
  208. on symbols or searching for particular symbols without adding them to
  209. an appropriate @samp{.def} file.
  210. @node Interface, Networking, Kernel, Hacking Xconq
  211. @section Interface
  212. The player interface is how actual players interact with the game.
  213. It need not be graphical or even particularly interactive,
  214. in fact it could even be a network server-style interface!
  215. However, this section will concentrate on the construction
  216. of interactive graphical interfaces.
  217. @menu
  218. * Interface Architecture::
  219. * Main Program::                
  220. * Startup Options::             
  221. * Progress Indication::         
  222. * Feedback and Control::        
  223. * Play Commands::                    
  224. * Error Handling::              
  225. * Textual Displays::            
  226. * Display Update::              
  227. * Types of Windows and Panels::  
  228. * Imaging::                     
  229. * Animation::                   
  230. * Game Designer Tools::         
  231. * Porting and Multiple Interfaces::  
  232. * Useful Displays::             
  233. * Useful Options::              
  234. * Debugging Aids::              
  235. * Guidelines and Suggestions::  
  236. @end menu
  237. @node Interface Architecture, Main Program, Interface, Interface
  238. @subsection Interface Architecture
  239. An interface is always compiled in, so it has complete access to the
  240. game state.  However, if your version of @i{Xconq} has any networking
  241. support, the interface should not modify kernel structures directly,
  242. but should instead use kernel routines.  The kernel routines will
  243. forward any state modifications to all other programs participating
  244. in a game, so that everybody's state remains consistent.
  245. A working interface must provide some level of capability in each
  246. of these areas:
  247. @itemize
  248. @item
  249. Main program.
  250. The interface includes the main application and any
  251. system-specific infrastructure, such as event handling.
  252. @item
  253. Interpretation of startup options.
  254. This includes choice of games, variants, and players.
  255. @item
  256. Display of game state.
  257. This includes both textual and graphical displays,
  258. both static and dynamic.
  259. @item
  260. Commands/gestures for unit tasks and actions,
  261. and for general state modifications.
  262. @item
  263. Display update in response to state changes.
  264. @item
  265. Realtime progress.
  266. Some game designs require the interface
  267. to support realtime.
  268. @item
  269. Error handling.
  270. @end itemize
  271. The file @code{skelconq.c} in the @code{kernel} directory is
  272. a good example of a minimum working interface.
  273. Don't let interfaces ever set kernel object values directly, always
  274. go through calls that can be ``siphoned'' for networking.
  275. @node Main Program, Startup Options, Interface Architecture, Interface
  276. @subsection Main Program
  277. The interface provides @code{main()} for @i{Xconq};
  278. this allows maximum flexibility in adapting to different environments.
  279. In a sense, the kernel is a large library that the
  280. interface calls to do game-related operations.
  281. There is a standard set of calls that need to be made during
  282. initialization.  The set changes from time to time, so the
  283. following extract from @file{skelconq} should not be taken as
  284. definitive:
  285. @example
  286.     init_library_path(NULL);
  287.     clear_game_modules();
  288.     init_data_structures();
  289.     parse_command_line(argc, argv, general_options);
  290.     load_all_modules();
  291.     check_game_validity();
  292.     parse_command_line(argc, argv, variant_options);
  293.     set_variants_from_options();
  294.     parse_command_line(argc, argv, player_options);
  295.     set_players_from_options();
  296.     parse_command_line(argc, argv, leftover_options);
  297.     make_trial_assignments();
  298.     calculate_globals();
  299.     run_synth_methods();
  300.     final_init();
  301.     assign_players_to_sides();
  302.     init_displays();
  303.     init_signal_handlers();
  304.     run_game(0);
  305. @end example
  306. Note that this sequence is only straight-through for a simple command
  307. line option program; if you have one or more game setup dialogs, then
  308. you choose which to call based on how the players have progressed
  309. through the dialogs.  The decision points more-or-less correspond to
  310. the different @code{parse_command_line} calls in the example.
  311. You may also need to interleave some interface-specific calls;
  312. for instance, if you want to display side emblems in a player/side
  313. selection dialog, then you will need to arrange for the emblem images
  314. to be loaded and displayable, rather than doing it as part of opening
  315. displays.
  316. Once a game is underway, the interface is basically self-contained,
  317. needing only to call @code{run_game} periodically to keep the
  318. game moving along.  @code{run_game} takes one argument which can
  319. be -1, 0, or 1.  If 1, then one unit gets to do one action, then
  320. the routine returns.  If 0, the calculations are gone through, but
  321. no units can act.  If -1, then all possible units will move before
  322. @code{run_game} returns.  This last case is not recommended for interactive
  323. programs, since moving all units in a large game may take a very long
  324. time; several minutes sometimes, and @code{run_game} may not necessarily
  325. call back to the interface very often.
  326. @node Startup Options, Progress Indication, Main Program, Interface
  327. @subsection Startup Options
  328. Although there are many different ways to get a game started,
  329. you have three main categories of functionality to support:
  330. 1) selection of the game to play, 2) setting of variants, and
  331. 3) selection of players.  For command-line-using programs,
  332. the file @code{cmdline.c} need only be linked in to provide
  333. all of this functionality.  For graphical interfaces, you will
  334. need to design appropriate dialogs.  This can be a lot of work,
  335. exacerbated by the fact that these dialogs will be the first
  336. things that new @i{Xconq} players see, and will therefore shape
  337. their opinions about the quality of the interface and of the game.
  338. [more detail about what has to be in dialogs?]
  339. Interface code should check all player specs, not proceed with initialization
  340. until these are all valid.
  341. Both standard and nonstandard variants should vanish from or be grayed out
  342. in dialog boxes if irrelevant to a selected game.
  343. @node Progress Indication, Feedback and Control, Startup Options, Interface
  344. @subsection Progress Indication
  345. Some synthesis methods are very slow, and become even
  346. slower when creating large games, so the kernel will announce a slow process,
  347. provide regular updates, and signal when the process is done.  The interface
  348. should display this in some useful way.  In general, progress should always
  349. be displayed, although one could postpone displaying anything until after
  350. the first progress update, calculate an estimated time to completion, and
  351. not display anything if that estimate is for less than a few seconds.
  352. However, this is probably unnecessary.
  353. @itemize
  354. @item
  355. @code{void announce_read_progress()}
  356. The kernel calls this regularly while reading game definitions.
  357. Interfaces running on slow machines should use this to indicate that
  358. everything is still working; for instance, the Mac interface animates
  359. a special cursor that indicates reading is taking place.
  360. @item
  361. @code{void announce_lengthy_process(char *msg)}
  362. The kernel calls this at the beginning of each synthesis.  The argument
  363. is a readable string that the interface can show to players.
  364. @item
  365. @code{void announce_progress(int pctdone)}
  366. The kernel may call this at milestones within a synthesis.
  367. The number ranges from 0 to 100.
  368. @item
  369. @code{void finish_lengthy_process()}
  370. The kernel calls this at the end of a synthesis.
  371. @end itemize
  372. @node Feedback and Control, Play Commands, Progress Indication, Interface
  373. @subsection Feedback and Control
  374. The interface should provide visible feedback for every successful unit
  375. action initiated directly by the player, but it need not do so for failures,
  376. unless they are serious.  It is better to prevent nonsensical input,
  377. for instance by disabling menus and control panel items.  Simple interfaces
  378. such as for character terminals will have to relax these rules somewhat.
  379. Interfaces should enable/disable display of lighting conditions.
  380. @node Play Commands, Error Handling, Feedback and Control, Interface
  381. @subsection Play Commands
  382. There is no single correct way to support direct player control over units.
  383. Although keyboard commands and mouse clicks are obvious choices,
  384. it would be very cool to allow a pen or mouse to sketch a movement plan,
  385. or to be able to give verbal orders...
  386. There is a common set of ASCII keyboard commands that are recommended
  387. for all @i{Xconq} interfaces that use a keyboard.
  388. These are defined in @code{kernel/cmd.def}.
  389. If you use these, @i{Xconq} players will be able to switch platforms
  390. and still use familiar commands.  @code{cmd.def} defines a single character,
  391. a command name, a help string, and a function name,
  392. always in the form @code{do_*}.
  393. However, @code{cmd.def} does not specify arguments, return types,
  394. or behavior of those functions, so each interface must still define
  395. its own command lookup and calling conventions.
  396. Prefixed number args should almost always be repetitions.
  397. If already fully fueled, refuel commands should come back immediately.
  398. A quit cmd can always take a player out of the game, but player may have
  399. to agree to resign.  Player can also declare willingness to quit or draw
  400. without actually doing so, then resolution requires that everybody agree.
  401. If quitting but others continuing on, also have option of being a
  402. spectator.  Could have notion of "leaving game without declaring entire
  403. game a draw" for some players.
  404. Allow for a timeout and default vote in case some voters have disappeared
  405. mysteriously.
  406. Must never force a player to stay in.
  407. Add a notion of login/logout so a side can be inactive but untouchable,
  408. possibly freezes entire game if a side is inactive.
  409. 1. if one player or no scoring
  410.     confirm, then shut player down
  411.     if one player, then shut game down
  412. 2. if side is considered a sure win (how to tell? is effectively a win
  413. condition then) or all sides willing to draw
  414.     confirm, take side out, declare a draw, shut player down
  415. 3. if all sides willing to quit
  416.     take entire game down
  417. 4. ask about resigning - if yes,
  418.     resign, close display, keep game running
  419.    if no, ask if willing to quit and/or draw, send msg to other sides
  420. Kernel support limited to must_resign_to_quit(side), similar tests.
  421. @node Error Handling, Textual Displays, Play Commands, Interface
  422. @subsection Error Handling
  423. The interface must provide implementations of these error-handling
  424. functions:
  425. @itemize
  426. @item
  427. @code{void low_init_warning(str)}
  428. This is for undesirable but not necessarily
  429. wrong things that happen while setting up a game.  For instance,
  430. if players start out too close or too far from each other, it will
  431. often affect the play of the game adversely, so the kernel issues
  432. a warning, therby giving the prospective players a chance to cancel
  433. the game and start over.  The kernel's warning message should
  434. indicate any likely results of continuing on, so the players can
  435. decide whether or not to chance it.
  436. @item
  437. @code{low_init_error(str)}
  438. This function should indicate a serious and unrecoverable error
  439. during initialization.  It should not return to its caller.
  440. @item
  441. @code{low_run_warning(str)}
  442. Warnings during the game are rare but not unknown.
  443. They are very often due to bugs in @code{Xconq}, so any
  444. occurrence should be investigated further.  It is possible
  445. for some game designs to have latent flaws that may result
  446. in a warning.
  447. In any case, the interface should allow the players to continue
  448. on, to save their game and quit, by calling @code{save_the_game},
  449. or else quit without saving anything.
  450. @item
  451. @code{low_run_error(str)}
  452. In the worst case, @i{Xconq} can get into a situation, such as
  453. memory exhaustion, where there is no way to continue.  The kernel
  454. will then call @code{run_error}, which should inform players that
  455. @i{Xconq} must shut itself down.  They do get the option of saving
  456. the game, and the routine should call @code{save_game_state??} to
  457. do this safely.  This routine should also not return to its caller.
  458. @item
  459. @code{printlisp(obj)}
  460. This is needed to print GDL objects to ``stdout'' or its equivalent.
  461. @end itemize
  462. @node Textual Displays, Display Update, Error Handling, Interface
  463. @subsection Textual Displays
  464. Text can take a long time to read, and can be difficult to provide
  465. in multiple human languages. (What, you thought only English speakers
  466. played @i{Xconq}?  Think again!)
  467. Therefore, text displays in the interfaces should be as minimal as
  468. possible, and derive from strings supplied in the game design,
  469. since they can be altered without rebuilding the entire program.
  470. (@i{Xconq} is not, at the moment, completely localizable,
  471. but that is a design goal.)
  472. @node Display Update, Types of Windows and Panels, Textual Displays, Interface
  473. @subsection Display Update
  474. Usually the interface's display is controlled by the player,
  475. but when @code{run_game} is executing, it will frequently change
  476. the state of an object in a way that needs to be reflected in the
  477. display immediately.  Examples include units leaving or entering
  478. a cell, sides losing or winning, and so forth.  The interface
  479. must define a set of callbacks that will be invoked by the kernel.
  480. @itemize
  481. @item
  482. @code{update_cell_display(side, x, y, rightnow)}
  483. [introduce area (radius or rect) update routines?]
  484. @item
  485. @code{update_side_display(side, side2, rightnow)}
  486. @item
  487. @code{update_unit_display(side, unit, rightnow)}
  488. @item
  489. @code{update_unit_acp_display(side, unit, rightnow)}
  490. @item
  491. @code{update_turn_display(side, rightnow)}
  492. @item
  493. @code{update_action_display(side, rightnow)}
  494. @item
  495. @code{update_action_result_display(side, unit, rslt, rightnow)}
  496. @item
  497. @code{update_fire_at_display(side, unit, unit2, m, rightnow)}
  498. @item
  499. @code{update_fire_at_display(side, unit, x, y, z, m, rightnow)}
  500. @item
  501. @code{update_event_display(side, hevt, rightnow)}
  502. @item
  503. @code{update_all_progress_displays(str, s)}
  504. @item
  505. @code{update_clock_display(side, rightnow)}
  506. @item
  507. @code{update_message_display(side, sender, str, rightnow)}
  508. @item
  509. @code{update_everything()}
  510. @end itemize
  511. Each of these routines has a flag indicating whether the change may be
  512. buffered or not.
  513. To ensure that buffered data is actually onscreen,
  514. the kernel may call @code{flush_display_buffers()},
  515. which the interface must define.
  516. @itemize
  517. @item
  518. @code{flush_display_buffers()}
  519. @end itemize
  520. These may or may not be called on reasonable sides, so the
  521. interface should always check first that @code{side} actually
  522. exists and has an active display.
  523. [If side has a "remote" display, then interface has to forward??
  524. No, because remote copy of game is synchronized and does own
  525. update_xxx calls more-or-less simultaneously]
  526. Note that this is as much as the kernel interests itself in displays.
  527. Map, list, etc drawing and redrawing are under the direct control
  528. of the interface code.
  529. Unix-hosted versions must provide @code{void close_displays()}
  530. for signal handlers to call.
  531. @node Types of Windows and Panels, Imaging, Display Update, Interface
  532. @subsection Types of Windows and Panels
  533. @i{Xconq} is best with a window-style interface, either tiled
  534. or overlapping.  Overlapping is more flexible, but also more
  535. complicated for players.
  536. In the following discussion, "window" will refer to a logically
  537. unified part of the display,
  538. which can be either a distinct window or merely a panel
  539. embedded in some larger window.
  540. The centerpiece window should be a map display.
  541. This will be the most-used window,
  542. since it will typically display more useful information
  543. than any other window.
  544. This means that it must also exhibit very good performance.
  545. When a game starts up, the map display should be centered
  546. on one of the player's units, preferably one close to the
  547. center of all the player's units.
  548. Another recommended window is a list of all the sides and where
  549. they stand in both the current turn and in the game as a whole.
  550. Each side's entry should include its name, a progress bar or
  551. other doneness indicator, and room for all the scores and scorekeepers
  552. that apply to that side.
  553. If possible, you should also implement
  554. some kind of "face" or group of faces/expressions for a side,
  555. so get a barbarian's face to repn a side instead of generic.
  556. Could have interface generate remarks/balloons if face clicked on,
  557. perhaps a reason for feelings, slogan, citation of agreement or broken
  558. agreement, etc.
  559. Need 5 faces for hostile, unfavorable, neutral, favorable, friendly/trusting.
  560. Overall status of side rules:
  561. all grayed: out of game
  562. grayed and x-ed out: lost
  563. ???: won
  564. Progress bar rules:
  565. missing: no units or no ai/no display
  566. grayed frame: no acting units
  567. empty solid frame: all acted
  568. part full, black: partly acted
  569. part full, gray: finished turn
  570. @node Imaging, Animation, Types of Windows and Panels, Interface
  571. @subsection Imaging
  572. Imaging is the process of drawing pictorial representations.
  573. Not every interface needs it. For instance the curses interface
  574. is limited to drawing two ASCII characters for each cell,
  575. and its imaging code just has to choose which two to draw.
  576. However, full-color bitmapped displays need more attention
  577. to the process of getting an image onscreen.
  578. No graphical icon should be drawn smaller than about 8x8, unless it's
  579. a text character drawn in two contrasting colors.
  580. Interfaces should cache optimal displays for each mag, not search
  581. for best image each time.
  582. Could allow 1-n "display variants" for all images, and for each orientation of
  583. border and connection.
  584. Imaging variations can be randomly selected by UI,
  585. but must be maintained so redraws are consistent.
  586. Allow the 64 bord/conn combos as single images, also advantage
  587. that all will be drawn at once.
  588. Draw partial cells around edges of a window, to indicate that the world
  589. continues on in that direction.
  590. Interface needs to draw only the terrain (but including connections and
  591. borders) in edge cells.
  592. Could draw grid by blitting large light pattern over world, do by inverting
  593. so is easy to turn on/off.  Do grids by changing hex size only in
  594. unpatterned color?
  595. Draw large hexagon or rect in unseen-color after clearing window to bg
  596. stipple (if unseen-color different).  Polygon should be inside area
  597. covered by edge hexes, so unseen area more obvious.
  598. Make large unseen-pattern that includes question marks?
  599. If picture not defined for a game, use some sort of nondescript image
  600. instead of leaving blank. (small "no picture available" for instance,
  601. like in yearbooks)
  602. To display night, could invert everything (b/w) or do 25/50% black (color)
  603. (let game set, so some games could be all-black at night, nothing visible)
  604. (have day/night coverage for each utype?)
  605. World is totally lit if dimensions < half of world circumference and all
  606. six corners of hexagon have same lighting.  If world totally dark, can draw
  607. darkening mask once for entire map.
  608. To display elevation, use deep blue -> light gray -> dark brown progression,
  609. maybe also contour lines?
  610. To draw contour lines, for each hex, look at each adj hex.  If on other
  611. side of contour's elev, compute interpolated point (in pixels) and save
  612. or draw a line to (one or both of the two) adj hex borders if they also
  613. have the contour line pass through.  Guaranteed that line is part of
  614. overall contour line.  Cheaper approach doesn't interpolate, just draws
  615. to midpoint of hex border (probably OK for small mags).
  616. Could maybe save contour lines once calculated (at each mag, lots of mem).
  617. If multiple connection or border types, the interface should draw them offset
  618. slightly from each other.
  619. @node Animation, Game Designer Tools, Imaging, Interface
  620. @subsection Animation
  621. In addition to basic imaging, you can also support requests
  622. for the playing of animations or @i{movies}.
  623. The kernel just calls @code{schedule_movie} to create one,
  624. and then @code{play_movies} when it is time to run all the
  625. movies that have been scheduled.  It is up to the interface
  626. to do something useful.  Note that the kernel is not aware
  627. of the movies' timing, so it is better not to call @code{run_game}
  628. until all the movies have finished playing.  (Yes, this would
  629. be a good future enhancement!)
  630. @itemize
  631. @item
  632. @code{schedule_movie(side, movie_type, args...)}
  633. @item
  634. @code{play_movies(sidemask)}
  635. Run all of the animations, sounds, etc that were scheduled
  636. previously, for the sides enabled in the side mask.
  637. It is allowable for the interface not to act on any user input
  638. while these are playing.
  639. @end itemize
  640. Several types of movies are predefined, so your interface can
  641. recognize them specially.  These include @code{movie_miss},
  642. @code{movie_hit}, @code{movie_death}, which are scheduled
  643. for the appropriate outcomes of combat.
  644. @node Game Designer Tools, Porting and Multiple Interfaces, Animation, Interface
  645. @subsection Game Designer Tools
  646. An interface is not required to provide any sort of online
  647. designing tools, or even to provide a way to enable the
  648. special design privileges.  Nevertheless, minimal tools
  649. can be very helpful, and you will often find that they are
  650. helpful in debugging the rest of the interface, since you
  651. can use them to construct test cases at any time.
  652. A basic set of design tools should include a way to enable
  653. and disable designing for at least one side, a command to
  654. create units of a given type, and some sort of tool to set
  655. the terrain type at a given location.  A full set would
  656. include ``painting'' tools for all area layers, including
  657. geographical features, materials, weather, side views,
  658. and so forth - about a dozen in all.
  659. A least one level of undo for designer actions is very
  660. desirable, although it may be hard to implement.
  661. A useful rule for layers is to save a layer's previous
  662. state at the beginning of each painting or other modification
  663. action, when the mouse button first goes down.
  664. The designer will often want to save only the part of the game
  665. being worked on, for instance only the units or only the terrain.
  666. The "save game" action should give designers a choice about
  667. what to save.  For units particularly, the designer should be
  668. able to save only some properties of units.  The most basic
  669. properties are type, location, side, and name/number.
  670. The unit id should not be saved by default, but should have
  671. its own option (not clear why).
  672. Note that because game modules are textual and can be
  673. moved easily from one system to another, it is entirely
  674. possible to use one @i{Xconq} (perhaps on a Mac) to design
  675. games to be played on a Unix box under X11, or vice versa.
  676. Transferring the imagery is more difficult, although there
  677. is some support for the process.
  678. @node Porting and Multiple Interfaces, Useful Displays , Game Designer Tools, Interface
  679. @subsection Porting and Multiple Interfaces
  680. In theory, it is possible to compile multiple interfaces
  681. into a single @i{Xconq} program, but this would be hard at best.
  682. They would have to be multiplexed appropriately and not
  683. conflict anywhere in the address space.
  684. Sometimes this is intrinsically impossible;
  685. how could you compile the Mac and X interfaces into the same
  686. program, and would the result be a Mac application, a Unix program,
  687. or what?
  688. @node Useful Displays, Useful Options, Porting and Multiple Interfaces, Interface
  689. @subsection Useful Displays
  690. This is a collection of minor but useful displays that might be worth
  691. adding to an interface.
  692. A ``mouse over'' is a line or two of text that describes what the
  693. mouse/pointer is currently pointing at, and which updates automatically
  694. as the player moves the pointer around.  This is better for high-bandwidth
  695. interfaces, since there may be a lot of updating involved.  The volume
  696. can be reduced slightly by only redisplaying when the mouse moves, or,
  697. better, when what is being looked at changes.  This is probably best done
  698. by recalculating the line of text and then comparing it to what has been
  699. drawn already, although if the display is very fast, you may not save much
  700. in drawing time.  One approx 40-char lines covers basic info, such as
  701. terrain type and unit type; more detail may require multiple long lines.
  702. @node Useful Options, Debugging Aids, Useful Displays, Interface
  703. @subsection Useful Options
  704. A ``follow action'' option scrolls the screen to where the last event
  705. happened, such as combat. [etc]
  706. @node Debugging Aids, Guidelines and Suggestions, Useful Options, Interface
  707. @subsection Debugging Aids
  708. @i{Xconq} is complicated enough that you can't expect to throw together
  709. a complete working interface over the weekend.
  710. Therefore, you should build some debugging aids into the interface.
  711. You can ifdef with the flag @code{DEBUGGING} so as to ensure the code
  712. won't be in final versions.
  713. Display unit id if closeups, toplines, etc, if debugging is on.
  714. @node Guidelines and Suggestions,  , Debugging Aids, Interface
  715. @subsection Guidelines and Suggestions
  716. Although as the interface builder, you are free to make it work in any
  717. way you like, there are a number of basic things you should do.
  718. Some of these are general user interface principles, others are specific
  719. to @i{Xconq}, usually based on experiences with the existing interfaces.
  720. Applying some of these guidelines will require judicious balancing between
  721. consistency with the different version of @i{Xconq} and consistency with
  722. the system you're porting to.
  723. [following items should be better organized, moved in with relevant sections]
  724. Draw single selected unit in a stack larger.
  725. Draw single selected occupant in UR corner next to transport, when at
  726. mags that show both transport and occs.
  727. There should always be some sort of "what's happening now" display
  728. so player doesn't wonder about apparently dead machine.
  729. Image tool should report which type of resource is generating a
  730. given image, so can find which to hack on (report for selected image only).
  731. Interfaces should ensure stability of display choices
  732. if random possibilities, so need to cache local decisions about
  733. appearance of units if multiple images to choose from, choice of
  734. text messages, etc.
  735. Rules of Interaction:
  736. 1. Player can get to any unit in any mode.
  737. 2. Any player can prevent a turn from completing(/progressing?),
  738.    unless a hard real limit is encountered.
  739. 3. All players see each others' general move/activity state, modes, etc.
  740. 4. Players can "nudge" each other.
  741. 5. Real time limits can be set for sides, turns, and games, both by players
  742.    and by scenarios.
  743. Player should be able to click on a desired unit or image, and effectively
  744. say "take this", either grabs directly or else composes a task to approach
  745. and capture.
  746. Unit closeups should be laid out individually for each type, too much
  747. variability to make a single format reasonable.
  748. Add option where game design can specify use or avoidance of masks
  749. with unit icons.
  750. Player could escape a loss by saving a game, then discarding save.
  751. Mplayers could register suspicion when player saves then quits -
  752. "You're not trying to cheat, are you?" - but can't prevent this.
  753. All interfaces should be able to bring up an "Instructions" window
  754. that informs player(s) about the current game, includes xrefs to all
  755. game design info.  Restrict help to generic and interface info only.
  756. Graph display should graphing of various useful values, such as amounts
  757. of units and materials over time, attitudes of sides, combat, etc.
  758. Maximal is timeline for all sides and units, usually too elaborate but
  759. allow tracking movement for some "important" units.  Note that move
  760. actions may be recorded anyway.
  761. Make specialized dialog for agreements, put name on top, then scrolling list of
  762. terms, then signers, then random bits (public/secret, etc).  Use for proposals
  763. also, so allow for "tentative" signers, desired signers who have not looked at
  764. agreement.  Be able to display truth of each term, but need test to know when
  765. a side can know the truth of a term?
  766. Interfaces should have a ``wake up dummy'' button that can be used by players
  767. who have finished their turn, to prod other players not yet done.
  768. Commands that are irrelevant for a game ought to be grayed out in
  769. help displays, and error messages should identify as completely invalid
  770. (or just not do anything, a la grayed Mac menu shortcuts).
  771. Should be able to drag out a route and have unit follow it (user input
  772. of a complete task sequence).
  773. Hack formatting so that variable-width fonts usually work reasonably.
  774. Add xref buttons to various windows to go to other relevant windows and
  775. focus in.
  776. The current turn or date should be displayed prominently and be visible
  777. somewhere by default.
  778. Add some high-level verbs as commands ("assault Berlin", "bomb London until
  779. destroyed").
  780. Don't draw outline boxes at mags that would let them get outside the hex.
  781. If dating view data, allow it to gray out rather than disappear entirely.
  782. Could even have a "fade time" for unit images...
  783. Even if display is textual, use red text (and other colors) to indicate
  784. dangerous conditions.
  785. Next/prev unit controls should change map focus, even if screen
  786. unaffected.
  787. In general, ability to "select" a unit implies ability to examine,
  788. but not control.  Control implies ability to select, however.
  789. Use a builtin color matching a color name if possible, otherwise
  790. use the imc definition.
  791. Connections may need to be drawn differently in each of the two hexes
  792. they involve, such as straits connecting to a sea.
  793. (what is this supposed to mean?)
  794. If cell cramped for space, show only one material type at a time,
  795. require redraw to show amounts of a different type.
  796. Draw time remaining both digitally and as hourglass, for all time
  797. limits in effect.
  798. Could tie map to follow a specified unit (or to flip there quickly
  799. a la SimAnt).
  800. Have a separate message window from notices, allow broadcasting w/o
  801. specific msg command? (a "talk" window)
  802. Redraw hexes exposed when a unit with a legend moves.
  803. Truncate or move legend if would overlap some other unit/legend.
  804. Put limits on the number of windows of each type, set up so will reuse
  805. windows, except for ones that are "staked down".
  806. Fix border removal so inter-hex boundary pixels are cleaned up also.
  807. Need a specialized window or display to check on current scores
  808. (showing actual situation vs what's still needed).
  809. (Show both scorekeepers actually in force, as well as the others.)
  810. Side display could also display scores relevant to that side.
  811. Every unit plan display should have a place to record notes and general
  812. info about the unit, add a slot to units also.  Use in scenarios.
  813. Need a command for when a player can explicitly change the self-unit.
  814. Players should be able to rename any named object.  The interface should
  815. also provide a button or control to run any namer that might be available
  816. to the unit.
  817. Be able to select unit number display indep of unit name display,
  818. and feature name display indep of unit names.
  819. Don't draw things that xform to 0 pixel areas,
  820. only draw the most important things if 1-4 pixels or so.
  821. If time/effort to do action is > length of game, then interface
  822. can disable that action permanently.
  823. Use moving bar or gray under black to indicate reserve/asleep units.
  824. @node Networking, Miscellany, Interface, Hacking Xconq
  825. @section Networking
  826. @i{Xconq} has been also been designed to allow for different kinds of
  827. networking strategies.
  828. The kernel/interface architecture can be exploited to build
  829. a true server/client @i{Xconq},
  830. by building an ``interface'' that manages IPC connections
  831. and calling this the server, and then writing separate interface
  832. programs that translate data at the other end of the IPC connection
  833. into something that a display could use.
  834. My previous attempt at this (ca 1989) was very slow and buggy,
  835. though, so this is not necessarily an easy thing to write.
  836. The chief problem is in keeping the client's view of thousands
  837. of interlinked objects (units, sides, cells, and so forth)
  838. consistent with the server.
  839. Most existing server/client games work by either restricting
  840. the state to a handful of objects,
  841. or by only handing the client display-prepared data
  842. rather than abstract data,
  843. or by reducing the update interval
  844. to minutes or hours.
  845. [When networking, all kernels must call with same values...]
  846. @node Miscellany, , Networking, Hacking Xconq
  847. @section Miscellany
  848. @menu
  849. * Versioning Standards::        
  850. * Coding Standards::
  851. * Pitfalls::
  852. * Rationale and Future Directions::
  853. @end menu
  854. @node Versioning Standards, Coding Standards, Miscellany, Miscellany
  855. @subsection Versioning Standards
  856. In version @var{7.x.y}, @var{x} should change only
  857. when some documented user-visible aspect of @i{Xconq} changes,
  858. whether in the interface or kernel.
  859. In particular, any additions to GDL, such as a new table or
  860. property, require a new @var{x} version.
  861. @var{y} is reserved for bug-fix releases, which can include
  862. the implementation of features that were documented but not
  863. working correctly or completely.
  864. The macro @code{VERSION} should also include a date in parentheses,
  865. formatted in ``military style'', as in ``8 Jul 1995''.
  866. Be sure to set the date to some approximation of the date of your
  867. most recent change to the sources.
  868. @node Coding Standards, Pitfalls, Versioning Standards, Miscellany
  869. @subsection Coding Standards
  870. The @i{Xconq} sources adhere to a number of coding standards that
  871. you should follow also.  While everyone has their individual style,
  872. it is important to the code's maintenance that the existing style
  873. be preserved.
  874. Always allocate by using @code{xmalloc}.  This routine checks for
  875. allocation validity and gives a useful error message if allocation
  876. fails, it zeroes the block so you can count on the newly allocated
  877. space being in a known state, and it collects statistical data, which
  878. is important to optimization.
  879. Always generate a random number by using @code{xrandom}.  This is
  880. a generator of known and consistent properties across all systems
  881. that @i{Xconq} runs on.
  882. Indent by 4, with tabs at 8.  This is effectively what you get in
  883. Emacs if you set @code{c-indent-level} to 4.  System-specific interfaces
  884. need not adhere to this rule..
  885. @node Pitfalls, Rationale and Future Directions, Coding Standards, Miscellany
  886. @subsection Pitfalls
  887. This chapter would not be complete without some discussion of the traps
  888. awaiting the unwary hacker.
  889. The Absolute Number One Hazard in hacking @i{Xconq} is to introduce
  890. code that does not work for @emph{all} game designs.
  891. It is all too easy to assume that, for instance, unit speeds are always
  892. less than 20, or airbases can only be built by infantry, or that worlds
  893. are always randomly-generated.
  894. These sorts of assumptions have caused no end of problems.
  895. Code should test preconditions, especially for dynamically-allocated
  896. game-specified objects, and it should be tested using the various
  897. test scripts in the test directory.
  898. The number two pitfall is to not account for all the possible interfaces.
  899. Not all interfaces have a single ``current unit'' or map window,
  900. and some communicate with multiple players or over a network connection.
  901. You should not assume that your hack is generally valid until you have
  902. tested it against everything in the library and test directories.
  903. The @code{test} directory contains scripts that will be useful for this,
  904. at least to Unix hackers.  See the @code{README} in that directory
  905. for more information.
  906. Another pitfall is to be sloppy about performance.  An algorithm that works
  907. fine in a small world with two sides and 50 units may be painfully slow
  908. in a large game. Or, the algorithm may allocate too much working space
  909. and wind up exhausting memory (this has often happened).
  910. You should familiarize yourself with the algorithms already used in @i{Xconq},
  911. since they have already been debugged and tuned, and many have been written
  912. as generically useful code (see the area-scanning functions in @code{world.c}
  913. for instance).
  914. If your new feature is expensive, then define a global and compute its value
  915. only once, either at the start of the game or when it becomes relevant.
  916. Such a global should be named @code{any_<feature>}.
  917. Similarly, complicated tests on unit types or sides should be calculated
  918. once and cached in a dynamically-allocated array.
  919. You may have noticed that @i{Xconq} sources have been liberally sprinkled
  920. with debugging code, and you may desire to add some yourself.  In this modern
  921. age of computing, powerful source-level debuggers are widely available,
  922. so there is no good reason to add debugging code that to do a job that
  923. would be better done by the debugger.  @i{Xconq} debugging output
  924. is generally designed to be useful for understanding average behavior,
  925. changes over time, and ``high-level transients'' such as thrashing in
  926. plan or task execution; information that is difficult to collect using only
  927. a debugger.  When adding new debug output, you should keep this
  928. principle in mind.  Also be aware that some of the automated testing scripts
  929. enable debug output, so if you add something that is uselessly voluminous,
  930. testing output may fill your disk prematurely!
  931. @node Rationale and Future Directions, , Pitfalls, Miscellany
  932. @subsection Rationale and Future Directions
  933. This is where I justify what I've done, and not done.
  934. Please note that although @i{Xconq} has considerable power,
  935. its design was expressly limited to a particular class of two-dimensional
  936. board-like strategy games, and that playability  is emphasized over
  937. generality.  For instance, I avoided the temptation to include a
  938. general-purpose language, since it opens up many difficult issues
  939. and makes it much harder for game designers to produce a desired
  940. game (after all, if game designers wanted to use a general-purpose
  941. programming language, they could just write C code!).  Similarly,
  942. full 3D, realtime maneuvering, continuous terrain, and other such goodies
  943. must await the truly ultimate game system.
  944. The real problem with a general-purpose language is that although
  945. everything is possible, nothing is easy.  Many ``adventure game
  946. writing systems'' have fallen into this trap; they end up being
  947. poor reimplementations of standard programming languages, and the
  948. sole support for adventure gaming amounts to a small program
  949. skeleton and a few library functions.  It would have been easier
  950. just to start with a pre-existing language and just write the
  951. skeleton and libraries!
  952. @i{Xconq}, on the other hand, provides extensive optimized support
  953. for random game setup, large numbers of units, game save/restore,
  954. computer opponents, and many other facets of a game.
  955. Game designers don't have to deal with
  956. the subleties of fractal terrain synthesis, or the ordering of
  957. terrain effects on units, or how to tell the computer opponents
  958. that airbases are sometimes good for refueling but never any
  959. good for transportation, or the myriad of other details that
  960. are wired into @i{Xconq}.
  961. In fact, a complete working game can be set up with less than
  962. a half-page of GDL.
  963. Even so, the current @i{Xconq} design allows for several layers
  964. of extensibility, as was described earlier in this chapter.
  965. There are also several major areas in which @i{Xconq}
  966. could be improved.
  967. Tables should be supplemented with general formulae, although
  968. such formulae will complicate AIs' analyses considerably,
  969. since tables are much easier to scan.  Formula-based game
  970. definition would work much better with AIs that are coded
  971. specifically for the game and compiled in; this is more-or-less
  972. possible now, but there is not yet a good way to keep AIs
  973. from being used in games where they would be inappropriate
  974. (it might be amusing to have a panzer general AI attempting
  975. to play Gettysburg, but the coding would have to be careful
  976. not to try to index nonexistent unit types).
  977. Currently everything is based on a single area of a single world.
  978. This could be extended to multiple areas in the world, perhaps
  979. at different scales, as well as to multiple worlds.
  980. However, even with its limitations, @i{Xconq} has provided,
  981. and will continue to provide, many years of enjoyable playing,
  982. designing, and hacking.  Go to it!
  983.